package com.mmy.controller.scenic;

import java.math.BigDecimal;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.mmy.domain.constparameter.TConstParameter;
import com.mmy.domain.scenic.TScenicOrder;
import com.mmy.domain.scenic.VScenicOrder;
import com.mmy.domain.scenic.VScenicPlan;
import com.mmy.domain.sys.TSysUser;
import com.mmy.service.impl.constparameter.ConstParameterServiceImpl;
import com.mmy.service.scenic.impl.ScenicOrderServiceImpl;
import com.mmy.service.scenic.impl.ScenicPlanServiceImpl;

/**
 * 类的介绍：电子票订单
 *
 * @author shangzl
 * @date 创建日期：
 * @version 1.0
 */
@Controller
public class ScenicOrderController {
	// Hanxl 整理 2020.10.29
	@Autowired
	ScenicOrderServiceImpl scenicOrderServiceImpl;
	@Autowired
	ScenicPlanServiceImpl scenicPlanServiceImpl;
	@Autowired
	ConstParameterServiceImpl constParameterServiceImpl;

	/**
	 * 函数功能说明：前台 新建电子票预留信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl 修改人hanxl
	 * @date 创建日期 修改时间 2021.01.15
	 */
	@RequestMapping(value = "/enterreservescenic")
	public String EnterReserveScenic(HttpServletRequest request, Model model) {

		// 查询该景区时间在计划日期内的计划

		List<VScenicPlan> lstScenicPlan = scenicPlanServiceImpl.findPlanValid(request.getParameter("iScenicID"));
		model.addAttribute("lstScenicPlan", lstScenicPlan);

		model.addAttribute("iScenicID", request.getParameter("iScenicID"));
		Format f = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		List<Map<String, String>> list = new ArrayList<>();
		for (int i = 0; i < 90; i++) {
			cal.add(Calendar.DAY_OF_MONTH, 1);
			cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND, 0);
			cal.set(Calendar.MILLISECOND, 0);
			Date today = cal.getTime();
			Map<String, String> map = new HashMap<>();
			map.put("date", f.format(today));
			List<BigDecimal> lstPrice = new ArrayList<BigDecimal>();
			for (VScenicPlan vScenicPlan : lstScenicPlan) {
				Date startDate = vScenicPlan.getStartDate();
				Date endDate = vScenicPlan.getEndDate();
				if (today.before(endDate) & startDate.before(today)) {
					BigDecimal price = vScenicPlan.getPrice();
					lstPrice.add(price);
				}
			}

			if (lstPrice.size() == 0) {
				continue;
			} else {
				BigDecimal min = Collections.min(lstPrice);
				map.put("price", min.toString());
				list.add(map);
			}

		}
		model.addAttribute("json", JSONObject.toJSONString(list));
		return "scenic/ReserveScenic";

	}

	/**
	 * 函数功能说明： 新建景区电子票订单信息提交
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.01.12
	 */
	@ResponseBody
	@RequestMapping(value = "/savereservescenic")
	public Map<String, Object> saveReserveScenic(@RequestParam("plan") String strScenicPlan,
			@RequestParam("order") String strScenicOrder, @RequestParam("useDate") String strUseDate,
			HttpSession session) {

		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		Map<String, Object> data = scenicOrderServiceImpl.createOrderScenic(strScenicPlan, strScenicOrder, strUseDate,
				sessionSysUser);

		return data;
	}

	/**
	 * 函数功能说明： 新建景区电子票订单信息提交 进入填写收据页面
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.01.12
	 */
	@RequestMapping(value = "/topayorderscenic")
	public String toPayOrderScenic(HttpServletRequest request, Model model) {
		String lstID = request.getParameter("lstID");
		// 拆分字符串
		String[] arrID = lstID.split(",");
		TScenicOrder dbScenicOrder = scenicOrderServiceImpl.findByID(Integer.parseInt(arrID[0]));
		model.addAttribute("iOrderAmount", dbScenicOrder.getOrderAmount());
		model.addAttribute("lstID", lstID);
		return "scenic/PayOrderScenic";
	}

	/**
	 * 函数功能说明：收据提交
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 shangzl 修改人hanxl
	 * @date 创建日期 2021.01.12
	 */
	@RequestMapping(value = "/savepayorderscenic")
	public String savePayOrderScenic(TScenicOrder tScenicOrder, HttpSession session, String lstID, Model model) {
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		List<TScenicOrder> lstScenicOrder = scenicOrderServiceImpl.updateScenicOrder(tScenicOrder, sessionSysUser,
				lstID);

		model.addAttribute("lstID", lstID);
		model.addAttribute("tScenicOrder", lstScenicOrder.get(0));
		model.addAttribute("lstScenicOrder", lstScenicOrder);
		return "scenic/PrintScenicOrder";

	}

	/**
	 * 函数功能说明： 预留转订单信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/enterpayorderscenic")
	public String EnterPayOrderScenic(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		// TScenicOrder tScenicOrder = tScenicOrderServiceImpl.findByID(iID);
		// model.addAttribute("tScenicOrder", tScenicOrder);

		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);

		return "webbackground/scenic/payorderscenic";

	}

	/**
	 * 函数功能说明： 修改景点预留信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/enterupdatereservescenic")
	public String EnterUpdateReserveScenic(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		// TScenicOrder tScenicOrder = tScenicOrderServiceImpl.findByID(iID);
		// model.addAttribute("tScenicOrder", tScenicOrder);
		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);

		return "webbackground/scenic/updatereservescenic";

	}

	@RequestMapping(value = "/updatereservescenic")
	public String UpdateReserveScenicBase(TScenicOrder tScenicOrder, HttpSession session, String ScenicID)
			throws Exception {
		try {
//			 定义一个新的实体类对象 
			// TScenicOrder dtScenicOrder =
			// tScenicOrderServiceImpl.findByID(tScenicOrder.getID());
			// dtScenicOrder.setReserveName(tScenicOrder.getReserveName());
			// dtScenicOrder.setReserveTel(tScenicOrder.getReserveTel());
			// dtScenicOrder.setOrderNumber(tScenicOrder.getOrderNumber());
			// dtScenicOrder.setMemo(tScenicOrder.getMemo());
			// dtScenicOrder.setModifyDate(new Date());

			// BigDecimal bPrice = dtScenicOrder.getPrice();
			// int iNumber = dtScenicOrder.getOrderNumber();
//
			// String strPlanID = dtScenicOrder.getOrderID().substring(6, 12);

			// int iPlanID = Integer.parseInt(strPlanID);
			// TScenicPlan tScenicPlan = tScenicPlanServiceImpl.findByPlanID(iPlanID);

			int sumNumber = 0;

			// List<VScenicOrder> lstScenicOrder =
			// tScenicOrderServiceImpl.findByPlanID(iPlanID);

			// for (int i = 0; i < lstScenicOrder.size(); i++) {

			// int iOrderNumber = lstScenicOrder.get(i).getOrderNumber();

			// sumNumber += iOrderNumber;

			// }

			// if (tScenicPlan.getNumber() - sumNumber < 0) {
			// return "test";
			// }

			// BigDecimal bNumber = new BigDecimal(iNumber);
			// dtScenicOrder.setOrderAmount(bPrice.multiply(bNumber));
			TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
			// dtScenicOrder.setReviser(tSysUser.getUserName());
			// tScenicOrderServiceImpl.save(dtScenicOrder);
			return "redirect:orderscenic?iScenicID=" + Integer.parseInt(ScenicID);

		} catch (Exception e) {

		}
		return null;
	}

	/**
	 * 函数功能说明： 取消预留
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/entercancelreservescenic")
	public String CancelReserveScenic(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		// TScenicOrder tScenicOrder = tScenicOrderServiceImpl.findByID(iID);

		// tScenicOrder.setOrderState((byte) 3);

		// tScenicOrderServiceImpl.save(tScenicOrder);

		// model.addAttribute("tScenicOrder", tScenicOrder);
		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);

		// VScenicBase vScenicBase = tScenicBaseServiceImpl.findByID(iScenicID);
		// model.addAttribute("vScenicBase", vScenicBase);

		// List<VScenicOrder> lstScenicOrder =
		// tScenicOrderServiceImpl.findByScenicID(iScenicID);
		// model.addAttribute("orderlist", lstScenicOrder);
//
		return "webbackground/scenic/orderscenic";

	}

	/**
	 * 函数功能说明： 修改景点订单信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/enterupdateorderscenic")
	public String EnterUpdateOrderScenic(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		// TScenicOrder tScenicOrder = tScenicOrderServiceImpl.findByID(iID);
		// model.addAttribute("tScenicOrder", tScenicOrder);
		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);

		return "webbackground/scenic/updateorderscenic";

	}

	@RequestMapping(value = "/updateorderscenic")
	public String UpdateOrderScenicBase(TScenicOrder tScenicOrder, HttpSession session, String ScenicID)
			throws Exception {
		try {
//			 定义一个新的实体类对象 
			// TScenicOrder dtScenicOrder =
			// tScenicOrderServiceImpl.findByID(tScenicOrder.getID());
			// dtScenicOrder.setOrderName(tScenicOrder.getOrderName());
			// dtScenicOrder.setOrderTel(tScenicOrder.getOrderTel());
			// dtScenicOrder.setOrderNumber(tScenicOrder.getOrderNumber());
			// dtScenicOrder.setMemo(tScenicOrder.getMemo());
			// dtScenicOrder.setModifyDate(new Date());

			// BigDecimal bPrice = dtScenicOrder.getPrice();
			int iNumber = tScenicOrder.getOrderNumber();
			BigDecimal bNumber = new BigDecimal(iNumber);
			// dtScenicOrder.setOrderAmount(bPrice.multiply(bNumber));
			TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
			// dtScenicOrder.setReviser(tSysUser.getUserName());
			// tScenicOrderServiceImpl.save(dtScenicOrder);
			return "redirect:orderscenic?iScenicID=" + Integer.parseInt(ScenicID);

		} catch (Exception e) {

		}
		return null;
	}

	/**
	 * 函数功能说明： 删除取消预留信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/delreservescenicbase")
	public String DelReserveScenicBase(String checkList, HttpServletRequest request, Model model) {

		String[] checklist = checkList.split(",");
		List<Integer> lstID = new ArrayList<>();

		for (String str : checklist) {
			lstID.add(Integer.parseInt(str));
		}

		// tScenicOrderServiceImpl.delScenicOrder(lstID);

		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);
		// VScenicBase vScenicBase = tScenicBaseServiceImpl.findByID(iScenicID);
		// model.addAttribute("vScenicBase", vScenicBase);

		// List<VScenicOrder> lstScenicOrder =
		// tScenicOrderServiceImpl.findByScenicID(iScenicID);
		// model.addAttribute("orderlist", lstScenicOrder);

		return "webbackground/scenic/orderscenic";
	}

	/**
	 * 函数功能说明： 删除取消订单信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/delorderscenicbase")
	public String DelOrderScenicBase(String checkList, HttpServletRequest request, Model model) {

		String[] checklist = checkList.split(",");
		List<Integer> lstID = new ArrayList<>();

		for (String str : checklist) {
			lstID.add(Integer.parseInt(str));
		}

		// tScenicOrderServiceImpl.delScenicOrder(lstID);

		int iScenicID = Integer.parseInt(request.getParameter("iScenicID"));
		model.addAttribute("iScenicID", iScenicID);

		// VScenicBase vScenicBase = tScenicBaseServiceImpl.findByID(iScenicID);
		// model.addAttribute("vScenicBase", vScenicBase);

		// List<VScenicOrder> lstScenicOrder =
		// tScenicOrderServiceImpl.findByScenicID(iScenicID);
		// model.addAttribute("orderlist", lstScenicOrder);

		return "webbackground/scenic/orderscenic";
	}

	/**
	 * 函数功能说明： 前台个人中心点击取消景点预留
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/entersceniccancelreserve")
	public String enterScenicCancelReserve(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		scenicOrderServiceImpl.updateState(iID, sessionSysUser);
		return "redirect:myscenicreserve";

	}

	/**
	 * 函数功能说明： 前台个人中心点击申请景点退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/enterscenicapplyrefund")
	public String enterScenicApplyRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		scenicOrderServiceImpl.updateRefundState(iID, sessionSysUser);
		return "redirect:myscenicorder";
	}

	/**
	 * 函数功能说明： 前台个人中心点击撤销景点退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/entersceniccancelrefund")
	public String enterScenicCancelRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		scenicOrderServiceImpl.updateCancelState(iID, sessionSysUser);
		return "redirect:myscenicrefund";
	}

	/**
	 * 函数功能说明：前台个人中心显示订单详情
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/myscenicinfo")
	public String toMyScenicInfo(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		TScenicOrder dbScenicOrder = scenicOrderServiceImpl.findByID(iID);
		model.addAttribute("dbScenicOrder", dbScenicOrder);

		String strOrderID = dbScenicOrder.getOrderID();
		int iPlanID = Integer.parseInt(strOrderID.substring(6, 12));

		VScenicPlan dbScenicPlan = scenicPlanServiceImpl.findByID(iPlanID);

		model.addAttribute("dbScenicPlan", dbScenicPlan);

		return "permanagement/MyScenicInfo";
	}

	/**
	 * 函数功能说明：后台显示所有订单信息
	 *
	 * @param 参数说明 tScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.12.29
	 */
	@RequestMapping(value = "/toscenicallorderindex")
	public String toScenicOrderIndex(HttpServletRequest request, Model model, String pageNumber, String pageSize,
			HttpSession session) {
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		String strScenicName = request.getParameter("strScenicName");
		String strOrderName = request.getParameter("strOrderName");
		String strOrderTel = request.getParameter("strOrderTel");
		String strOrderDate = request.getParameter("strOrderDate");
		String strOrderState = request.getParameter("strOrderState");

		List<VScenicOrder> lstScenicOrder = new ArrayList<VScenicOrder>();
		HashMap<String, Integer> mapPage = new HashMap<String, Integer>();
		// 管理员登录 默认查看所有 并分页 带搜索条件
		if (sessionSysUser.getUserID() == 0) {
			lstScenicOrder = scenicOrderServiceImpl.findBySeachAdministrator(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate, strOrderState);
			mapPage = scenicOrderServiceImpl.mapSeachAdministrator(pageNumber, pageSize, strScenicName, strOrderName,
					strOrderTel, strOrderDate, strOrderState);
		} else {
			// 非管理员登录 默认查看自家公司的景区所有订单 以及订单操作人是自己公司的订单
			// 搜索时 输入搜索条件同时满足上述条件
			lstScenicOrder = scenicOrderServiceImpl.findBySearchOperator(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate, strOrderState, sessionSysUser);
			mapPage = scenicOrderServiceImpl.mapSearchOperator(pageNumber, pageSize, strScenicName, strOrderName,
					strOrderTel, strOrderDate, strOrderState, sessionSysUser);
		}

		model.addAttribute("lstScenicOrder", lstScenicOrder);

		model.addAttribute("iPageNo", mapPage.get("iPageNo"));
		model.addAttribute("iTotalCount", mapPage.get("iTotalCount"));
		model.addAttribute("iMaxPage", mapPage.get("iMaxPage"));
		model.addAttribute("iPageSize", mapPage.get("iPageSize"));
		model.addAttribute("strScenicName", strScenicName);
		model.addAttribute("strOrderName", strOrderName);
		model.addAttribute("strOrderTel", strOrderTel);
		model.addAttribute("strOrderDate", strOrderDate);
		model.addAttribute("strOrderState", strOrderState);
		return "webbackground/scenicmanagement/ScenicAllOrderIndex";
	}

	/**
	 * 函数功能说明：后台显示未入园的订单信息
	 *
	 * @param 参数说明 tScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.12.29
	 */
	@RequestMapping(value = "/toscenicunusedorderindex")
	public String toScenicUnUsedOrderIndex(HttpServletRequest request, Model model, String pageNumber, String pageSize,
			HttpSession session) {

		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		String strScenicName = request.getParameter("strScenicName");
		String strOrderName = request.getParameter("strOrderName");
		String strOrderTel = request.getParameter("strOrderTel");
		String strOrderDate = request.getParameter("strOrderDate");
		List<VScenicOrder> lstScenicOrder = new ArrayList<VScenicOrder>();
		HashMap<String, Integer> mapPage = new HashMap<String, Integer>();

		// 管理员登录 默认查看所有 并分页 带搜索条件
		if (sessionSysUser.getUserID() == 0) {
			lstScenicOrder = scenicOrderServiceImpl.findBySeachAdministratorUnUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate);
			mapPage = scenicOrderServiceImpl.mapSeachAdministratorUnUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate);
		} else {
			// 非管理员登录 默认查看自家公司的景区所有订单 以及订单操作人是自己公司的订单
			// 搜索时 输入搜索条件同时满足上述条件
			lstScenicOrder = scenicOrderServiceImpl.findBySearchOperatorUnUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate, sessionSysUser);
			mapPage = scenicOrderServiceImpl.mapSearchOperatorUnUsed(pageNumber, pageSize, strScenicName, strOrderName,
					strOrderTel, strOrderDate, sessionSysUser);
		}

		model.addAttribute("lstScenicOrder", lstScenicOrder);

		model.addAttribute("iPageNo", mapPage.get("iPageNo"));
		model.addAttribute("iTotalCount", mapPage.get("iTotalCount"));
		model.addAttribute("iMaxPage", mapPage.get("iMaxPage"));
		model.addAttribute("iPageSize", mapPage.get("iPageSize"));
		model.addAttribute("strScenicName", strScenicName);
		model.addAttribute("strOrderName", strOrderName);
		model.addAttribute("strOrderTel", strOrderTel);
		model.addAttribute("strOrderDate", strOrderDate);
		return "webbackground/scenicmanagement/ScenicUnUsedOrderIndex";
	}

	/**
	 * * 函数功能说明： 未入园的订单允许退款
	 * 
	 * 登录人所属公司和景区所属公司相等 订单操作人为游客 或者订单操作员与登录人所属公司相同
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl 修改人hanxl
	 * @date 创建日期 修改时间2021.01.06
	 */

	@RequestMapping(value = "/backtorefundorderscenic")
	public String backToRefundOrderScenic(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TScenicOrder dbScenicOrder = scenicOrderServiceImpl.findByID(iID);
		model.addAttribute("dbScenicOrder", dbScenicOrder);
		return "webbackground/scenicmanagement/RefundOrderScenic";

	}

	/**
	 * * 函数功能说明： 后台未入园的的订单 提交退款信息
	 *
	 * 登录人所属公司和景区所属公司相等 订单操作人为游客 或者订单操作员与登录人所属公司相同
	 * 
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl 修改人hanxl
	 * @date 创建日期 修改时间2021.01.06
	 */
	@RequestMapping(value = "/saverefundorderscenic")
	public String saveRefundOrderScenic(TScenicOrder tScenicOrder, HttpSession session, Model model) {
//获取session
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");

//修改退单状态以及退单金额  以及订单状态
		TScenicOrder dbScenicOrder = scenicOrderServiceImpl.updateRefund(tScenicOrder, sessionSysUser);
		model.addAttribute("dbScenicOrder", dbScenicOrder);
		return "webbackground/scenicmanagement/PrintRefundOrderScenic";
	}

	/**
	 * * 函数功能说明： 后台未入园的的订单 退单流程改为申请退单
	 *
	 * 登录人所属公司与景区所属公司不相等 操作人与登录人所属公司相等
	 * 
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl 修改人hanxl
	 * @date 创建日期 修改时间2021.01.06
	 */
	@ResponseBody
	@RequestMapping(value = "/saveupdateprocessscenic")
	public Map<String, String> saveUpdateProceddScenic(HttpServletRequest request, HttpSession session, Model model) {
//获取session
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		int iID = Integer.parseInt(request.getParameter("iID"));
//修改退单状态为申请退单
		Map<String, String> map = scenicOrderServiceImpl.updateProcess(iID, sessionSysUser);

		return map;
	}

	/**
	 * * 函数功能说明： 未入园的订单退款
	 * 
	 * 登录人所属公司和景区所属公司相等 订单操作人与登录人所属公司不相同 且订单状态为申请退款
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期2021.01.06
	 */

	@RequestMapping(value = "/backtoscenicrefundorder")
	public String backToScenicRefundOrder(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TScenicOrder dbScenicOrder = scenicOrderServiceImpl.findByID(iID);
		model.addAttribute("dbScenicOrder", dbScenicOrder);
		return "webbackground/scenicmanagement/ScenicRefundOrder";

	}

	/**
	 * * 函数功能说明： 后台未入园的的订单 提交退款信息
	 *
	 * 登录人所属公司和景区所属公司相等 订单操作员与登录人所属公司不相同 订单退款流程为申请退款 填写退款流程以及退款金额提交
	 * 
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人hanxl
	 * @date 创建日期 2021.01.06
	 */
	@RequestMapping(value = "/savescenicrefundorder")
	public String saveScenicRefundOrder(TScenicOrder tScenicOrder, HttpSession session, Model model) {
//获取session
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");

//修改退单状态以及退单金额
		scenicOrderServiceImpl.updateRefundAndProcess(tScenicOrder, sessionSysUser);

		return "redirect:toscenicunusedorderindex";
	}

	/**
	 * 函数功能说明：后台显示近期待使用的订单信息
	 *
	 * @param 参数说明 tScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.12.29
	 */
	@RequestMapping(value = "/toscenicrecentlyuseorderindex")
	public String toScenicRecentlyUseOrderIndex(HttpServletRequest request, Model model, String pageNumber,
			String pageSize, HttpSession session) {
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		// 参数设置查询确定近期的天数范围

		String maxDayText = "景区近期待使用天数";
		TConstParameter dbConstParameter = constParameterServiceImpl.getByText(maxDayText);
		int iMaxDay = dbConstParameter.getValue().intValue();
		String strScenicName = request.getParameter("strScenicName");
		String strOrderName = request.getParameter("strOrderName");
		String strOrderTel = request.getParameter("strOrderTel");
		String strOrderDate = request.getParameter("strOrderDate");
		List<VScenicOrder> lstScenicOrder = new ArrayList<VScenicOrder>();
		HashMap<String, Integer> mapPage = new HashMap<String, Integer>();
		// 管理员登录 默认查看所有 并分页 带搜索条件
		if (sessionSysUser.getUserID() == 0) {
			lstScenicOrder = scenicOrderServiceImpl.findBySeachAdministratorRecentlyUse(pageNumber, pageSize,
					strScenicName, strOrderName, strOrderTel, iMaxDay, strOrderDate);
			mapPage = scenicOrderServiceImpl.mapSeachAdministratorRecentlyUse(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, iMaxDay, strOrderDate);
		} else {
			// 非管理员登录 默认查看自家公司的景区所有订单 以及订单操作人是自己公司的订单
			// 搜索时 输入搜索条件同时满足上述条件
			lstScenicOrder = scenicOrderServiceImpl.findBySearchOperatorRecentlyUse(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, sessionSysUser, iMaxDay, strOrderDate);
			mapPage = scenicOrderServiceImpl.mapSearchOperatorRecentlyUse(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, sessionSysUser, iMaxDay, strOrderDate);
		}

		model.addAttribute("lstScenicOrder", lstScenicOrder);

		model.addAttribute("iPageNo", mapPage.get("iPageNo"));
		model.addAttribute("iTotalCount", mapPage.get("iTotalCount"));
		model.addAttribute("iMaxPage", mapPage.get("iMaxPage"));
		model.addAttribute("iPageSize", mapPage.get("iPageSize"));
		model.addAttribute("strScenicName", strScenicName);
		model.addAttribute("strOrderName", strOrderName);
		model.addAttribute("strOrderTel", strOrderTel);
		model.addAttribute("strOrderDate", strOrderDate);
		return "webbackground/scenicmanagement/ScenicRecentlyUseOrderIndex";
	}

	/**
	 * 函数功能说明：后台显示已使用的订单信息
	 *
	 * @param 参数说明 tScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.12.29
	 */
	@RequestMapping(value = "/toscenicusedorderindex")
	public String toScenicUsedOrderIndex(HttpServletRequest request, Model model, String pageNumber, String pageSize,
			HttpSession session) {
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		String strScenicName = request.getParameter("strScenicName");
		String strOrderName = request.getParameter("strOrderName");
		String strOrderTel = request.getParameter("strOrderTel");
		String strOrderDate = request.getParameter("strOrderDate");
		List<VScenicOrder> lstScenicOrder = new ArrayList<VScenicOrder>();
		HashMap<String, Integer> mapPage = new HashMap<String, Integer>();

		// 管理员登录 默认查看所有 并分页 带搜索条件
		if (sessionSysUser.getUserID() == 0) {
			lstScenicOrder = scenicOrderServiceImpl.findBySeachAdministratorUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate);
			mapPage = scenicOrderServiceImpl.mapSeachAdministratorUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate);
		} else {
			// 非管理员登录 默认查看自家公司的景区所有订单 以及订单操作人是自己公司的订单
			// 搜索时 输入搜索条件同时满足上述条件
			lstScenicOrder = scenicOrderServiceImpl.findBySearchOperatorUsed(pageNumber, pageSize, strScenicName,
					strOrderName, strOrderTel, strOrderDate, sessionSysUser);
			mapPage = scenicOrderServiceImpl.mapSearchOperatorUsed(pageNumber, pageSize, strScenicName, strOrderName,
					strOrderTel, strOrderDate, sessionSysUser);
		}

		model.addAttribute("lstScenicOrder", lstScenicOrder);

		model.addAttribute("iPageNo", mapPage.get("iPageNo"));
		model.addAttribute("iTotalCount", mapPage.get("iTotalCount"));
		model.addAttribute("iMaxPage", mapPage.get("iMaxPage"));
		model.addAttribute("iPageSize", mapPage.get("iPageSize"));
		model.addAttribute("strScenicName", strScenicName);
		model.addAttribute("strOrderName", strOrderName);
		model.addAttribute("strOrderTel", strOrderTel);
		model.addAttribute("strOrderDate", strOrderDate);
		return "webbackground/scenicmanagement/ScenicUsedOrderIndex";
	}

	/**
	 * 函数功能说明：后台显示已使用的订单信息 结账
	 *
	 * @param 参数说明 tScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2021.01.28
	 */
	@RequestMapping(value = "/updateremittancestatescenic")
	public String updateRemittanceStateScenic(String checkList, HttpSession session) {
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		scenicOrderServiceImpl.updateRemittanceStateScenic(checkList, sessionSysUser);

		return "redirect:toscenicusedorderindex";
	}

	/**
	 * 函数功能说明：后台显示订单详情
	 *
	 * @param 参数说明 vScenicOrder
	 * @return 返回值说明 jsp页面
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.01.28
	 */
	@RequestMapping(value = "/scenicorderinfo")
	public String scenicOrderInfo(HttpServletRequest request, Model model) {

		VScenicOrder dbScenicOrder = scenicOrderServiceImpl.findByID(request.getParameter("iID"));
		model.addAttribute("dbScenicOrder", dbScenicOrder);
		return "webbackground/scenicmanagement/OrderScenicInfo";
	}
}
